<template>
    <div>
        <van-checkbox-group v-model="ids">
                <van-checkbox :name="i.id" v-for='i in resourcelist'>{{i.name}}</van-checkbox>
               
              </van-checkbox-group>
        <van-button @click="add" color="linear-gradient(to left, #ff6034,#7232dd)">添加</van-button>
    </div>
</template>

<script>
    export default {
        data(){
            return{
                role_id:this.$route.query.id,

                resourcelist:[],
                ids:[]
            }
        },
        methods:{
            get_resources(){
                this.$axios.get('resourcesM').then(res=>{
                    this.resourcelist=res.data.list
                    this.getResByid()
                })
            },
            add(){
                this.$axios.post('setresources',{'role_id':this.role_id,'ids':this.ids}).then(res=>{
                    alert('配置成功')
                })
            },
            //查询此角色对应的资源ids
            getResByid(){
                this.$axios.get('resourcesM?id='+this.role_id).then(res=>{
                    this.ids = res.data.list
                })
            }
        },
        mounted(){
            this.get_resources()
        }
    }
</script>

<style scoped>

</style>